__author__ = 'vivienfanghua'
# coding=utf-8
import math
import matplotlib.pyplot as plt

def CA(array,func):
    result=[]
    for i in range(len(array)):
        for j in range(100):
            x=i+1.0*j/100
            data_input=array[int(x)]
            data_cos=func(x*math.pi)
            # result.append(data_input and (not data_cos))
            result.append(data_input*data_cos)
    return result

if __name__=="__main__":
    code=[1,-1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1]
    result=CA(code,math.cos)
    x=range(len(code)*100)
    x=[1.0*i/100 for i in x]
    plt.figure(figsize=(8,4))
    plt.plot(x,result,label=u"$Modulated code$",color="red",linewidth=2)
    plt.legend()
    plt.show()